package com.greensam.pixelengine.pojo.vo.picture.response;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.greensam.pixelengine.pojo.base.BaseDto;
import com.greensam.pixelengine.pojo.emuns.ReviewStatusEnum;
import com.greensam.pixelengine.pojo.entity.PicturePo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

import java.io.Serial;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

/**
 * @author Macro_Ray
 * @since 2025/7/2 14:04
 */
@Getter
@Setter
@Schema(title = "图片响应对象")
public class PictureVo extends BaseDto {

    @Serial
    private static final long serialVersionUID = 1L;

    @Schema(title = "图片ID")
    private Long id;

    @Schema(title = "图片地址")
    private String url;

    @Schema(title = "缩略图地址")
    private String thumbnailUrl;

    @Schema(title = "图片名称")
    private String name;

    @Schema(title = "图片描述")
    private String description;

    @Schema(title = "图片分类")
    private String category;

    @Schema(title = "图片标签")
    private List<String> tags;

    @Schema(title = "图片大小")
    private Long picSize;

    @Schema(title = "图片宽度")
    private Integer picWidth;

    @Schema(title = "图片高度")
    private Integer picHeight;

    @Schema(title = "图片宽高比例")
    private Double picScale;

    @Schema(title = "图片格式")
    private String picFormat;

    @Schema(title = "图片创建时间")
    private LocalDateTime createTime;

    @Schema(title = "图片更新时间")
    private LocalDateTime updateTime;

    @Schema(title = "图片上传用户")
    private Long userId;

    @Schema(title = "审核状态")
    private ReviewStatusEnum reviewStatus;

    @Schema(title = "审核人")
    private Long reviewBy;

    @Schema(title = "审核时间")
    private LocalDateTime reviewTime;

    @Schema(title = "审核信息")
    private String reviewMessage;

    @Schema(title = "图片空间ID")
    private Long spaceId;

    @Schema(title = "图片主色调")
    private String picColor;

    /**
     * 封装类转实体类
     */
    public static PicturePo pictureVo2PicturePo(PictureVo pictureVo) {
        if (Objects.isNull(pictureVo)) {
            return null;
        }
        PicturePo picturePo = BeanUtil.copyProperties(pictureVo, PicturePo.class);
        picturePo.setTags(JSONUtil.toJsonStr(pictureVo.getTags()));
        picturePo.setCreateBy(pictureVo.getUserId());
        picturePo.setUpdateBy(pictureVo.getUserId());
        return picturePo;
    }

    /**
     * 实体类转封装类
     */
    public static PictureVo picturePo2PictureVo(PicturePo picturePo) {
        if (Objects.isNull(picturePo)) {
            return null;
        }
        PictureVo pictureVo = BeanUtil.copyProperties(picturePo, PictureVo.class);
        pictureVo.setTags(JSONUtil.toList(JSONUtil.parseArray(picturePo.getTags()), String.class));
        pictureVo.setUserId(picturePo.getCreateBy());
        return pictureVo;
    }
}
